/**
 * 商品表
 */
import {BaseEntity, Column, Entity, OneToMany, PrimaryGeneratedColumn} from "typeorm";
import {ApiProperty} from "@nestjs/swagger";
import {StatusEnum, StatusEnumComment} from "../common/enum/StatusEnum";
import { GoodsPrice } from "./GoodsPrice";
import { IsNotEmpty } from "class-validator";
import { Validate_Mods } from "src/common/enum/ValidateModsEnum";
import { type } from "os";
import { Stock } from "./Stock";

@Entity()
export class Goods extends BaseEntity{

    constructor(id?: number, goodsCode?: string, goodsName?: string, status?: number, niki?: string, imgDir?: string) {
        super();
        this.id = id;
        this.goodsCode = goodsCode;
        this.goodsName = goodsName;
        this.status = status;
        this.niki = niki;
        this.imgDir = imgDir;
    }

    @ApiProperty({description: "主键ID"})
    @IsNotEmpty({message: "id不能为空!", groups: [ Validate_Mods.delete, Validate_Mods.update]})
    @PrimaryGeneratedColumn({comment: "主键ID"})
    id: number;

    @ApiProperty({description: "商品编码"})
    @IsNotEmpty({message: "商品编码不能为空!", groups: [Validate_Mods.detail, Validate_Mods.create]})
    @Column({comment: "商品编码", name: "goods_code", length: 50,  unique: true,})
    goodsCode: string;

    @ApiProperty({description: "商品名称"})
    @IsNotEmpty({message: "商品名称不能为空!", groups: [Validate_Mods.create]})
    @Column({comment: "商品名称", name: "goods_name", length: 50,})
    goodsName: string;

    @ApiProperty({description: StatusEnumComment, default: StatusEnum.AVAILABLE})
    @Column({comment: StatusEnumComment, default: StatusEnum.AVAILABLE})
    status: number;

    @ApiProperty({description: "商品简称：百事可乐 => BSKL,bskl"})
    @Column({comment: "商品简称：百事可乐 => BSKL", length: 80, nullable: true})
    niki: string;

    @ApiProperty({description: "图片路径"})
    @Column({comment: "img_dir", length: 1024, nullable: true})
    imgDir: string;

    /**
     * 关联关系
     */
    @ApiProperty({description: "价格"})
    @OneToMany(type => GoodsPrice, price => price.goods, {createForeignKeyConstraints: false})
    goodsPriceList: GoodsPrice[];

    @ApiProperty({description: "库存list"})
    @OneToMany(type => Stock, stock => stock.goods, {createForeignKeyConstraints: false})
    stockList: Stock[];
}
